<?php

namespace app\admin\model;

use think\Db;
use think\Model;

class Role extends Model
{
           public function getALL()
    {
//        $result=Db::table('hb_user')->select();

        //        查询所有的角色信息
        $rolelist=Db::table('hb_role')
            ->field(['id','rolename'])
            ->select();
//        dump($rolelist);


        $arr=$rolelist;
        $test=null;

        foreach ($rolelist as $c=>$v) {
//          查询对应角色的权限信息
            $pmlist = Db::table(['hb_permission' => 'p', 'role_permission' => 'rp'])
                ->field(['p.permission', 'rp.r_id'])
                ->where('p.id=rp.p_id')
                ->where('rp.r_id', $v['id'])
                ->select();
//            dump($pmlist);

            foreach ($pmlist as $k=>$v)
            {
                if ($test==$v['r_id']){
                    array_push($a,$v['permission']);

                }else{
                    $test=$v['r_id'];
                    $a=array($v['permission']);
                }
//                拼凑出需要的数组
                $arr[$c]['permission']=$a;
            }
        }
        return $arr;
    }

}
